package search;

public class BinarySearch {

    public static void main(String[] args) {
        int[] arr = { 0, 4, 6, 8, 14, 25, 31 };
        System.out.println(binarySearch(arr, 0, arr.length - 1, -2));
    }

    public static int binarySearch(int[] arr, int left, int right, int v) {
        if (left > right) {
            return -1;
        }
        int index = (left + right) / 2;
        int m = arr[index];
        if (v < m) {
            return binarySearch(arr, left, index - 1, v);
        } else if (v > m) {
            return binarySearch(arr, index + 1, right, v);
        } else {
            return index;
        }

    }

}
